var nowTime = document.getElementById('nowTime');
var ssyt = document.getElementById('ssyt');
var ssje = document.getElementById('ssje');
var scqk = document.getElementById('scqk'); //上次欠费
var ssqk = document.getElementById('ssqk'); //欠费
var documentNumber = document.getElementById('documentNumber');
var ssyt_money = 0;
var scqk_money = 0;
var ssje_money = 0;
var ssqk_money = 0;
var abbreviation = document.getElementById("abbreviation").value;
var operationTime = document.getElementById("operationTime").value;
var reservationsId = document.getElementById("reservationsId").value;
var getTime = document.getElementById("getTime").value;
var rechargeTime = document.getElementById("rechargeTime").value;
if (operationTime != null) {
    nowTime.innerText = rechargeTime.substring(0, 19);
} else {
    nowTime.innerText = getNowFormatDate();
}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
};

$.ajax({
    url: Feng.ctxPath + "/consultant/getOpenPrintTK",
    type: "post",
    data: {
        "operationTime": operationTime,
        "reservationsId": reservationsId,
        "abbreviation": abbreviation,
        "getTime": getTime,
    },
    success: function (data) {
        var arr = data;
        var plan_box = document.getElementById('plan_box');
        scqk_money += 0.00;
        ssqk_money += 0.00;
        for (var i = 0; i < arr.length; i++) {
            var plan_child = document.createElement('div');
            if (arr[i].payServiceName == null || arr[i].payServiceName == "") {
                var str = " ";
                plan_child.innerHTML = str;
                plan_box.appendChild(plan_child);
            } else {
                var str = '<div style="display: flex;height: 24px;line-height: 24px;margin-top: 3px;">' +
                    '<div style="flex: 4;text-indent: 1em;" id="disposal">' + arr[i].payServiceName + '</div>' +
                    '<div style="flex: 4;text-align: left" id="number">' + arr[i].totleArrears + '</div>' +
                    '</div>';
                plan_child.innerHTML = str;
                plan_box.appendChild(plan_child);
                scqk_money = parseFloat(arr[0].scarrears);
                ssqk_money = parseFloat(arr[0].accountArrears);
            }
        }
        scqk.innerText = scqk_money.toFixed(2);
        ssqk.innerText = ssqk_money.toFixed(2);
        $.ajax({
            url: Feng.ctxPath + "/consultant/getCheckoutMethod",
            type: "post",
            data: {
                "reservationsId": reservationsId,
                "getTime": getTime,
            },
            success: function (data1) {
                var str = "";
                for (var k = 0; k < data1.length; k++) {
                    str += data1[k].checkoutMethod + " " + data1[k].actualAccountBalance.toFixed(2);
                    ssyt_money += parseFloat(data1[k].actualAccountBalance);
                    ssje_money += parseFloat(data1[k].actualAccountBalance);
                    documentNumber.innerText = data1[k].documentNumber;
                }
                ssyt.innerText = ssyt_money.toFixed(2);
                ssje.innerText = ssje_money.toFixed(2);
            },
            error: function (data1) {
                alert('没有权限，请联系管理员!');
            }
        });
    },
    error: function (data) {
        alert('没有权限，请联系系统管理员!');
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    }
});

var bt = document.getElementById("bt");
var div_print = document.getElementById("div_print");
$("#bt").click(function () {//打印代码
    printdiv(div_print);
    if(window.parent.$("#isDorj").val() == 'jz'){
        parent.layer.close(parent.layer.getFrameIndex(window.name))
    }else if(window.parent.$("#isDorj").val() == 'dd'){
        window.parent.location.reload();
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    }
});

$("#cancel").click(function () {
    if (window.parent.$("#isDorj").val() == 'jz'){
        parent.layer.close(parent.layer.getFrameIndex(window.name))
    } else if (window.parent.$("#isDorj").val() == 'dd'){
        window.parent.location.reload();
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    } else {
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    }
});

function printdiv(printpage) {
    var newstr = printpage.innerHTML;
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = newstr;
    window.print();
    document.body.innerHTML = oldstr;
    return false;
}